﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tìm kiếm</title>
<link href="Css/cc.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div class="wrapper">
<?php include 'menu.php'; ?>
<div class="content">
<div class="bigleft">
        	<div class="bmmenu">
            	<div class="bmenu">
                	<ul>
                                <?php include 'connect.php';
                                    $menu = $con->query("Select * from category");
                                    while ($row = mysqli_fetch_array($menu)) {
                                ?>
                            <li>
                                <div><a href="product.php?dmcha=<?php echo $row['id'];?>"><?php echo $row["name"] ?></a></div>
                                    <ul>
                                        <?php include 'connect.php';
                                    $menu2 = $con->query("Select * from categorydetail where category_id=".$row['id']);
                                    while ($row2 = mysqli_fetch_array($menu2)) {
                                ?>
                                        <div><li><a href="product.php?dmcon=<?php echo $row2['id'];?>"><?php echo $row2["name"] ?></a></li></div>
                                        <?php } ?>
                                    </ul>
                            </li>
                        
                                    <?php } ?>
                    </ul>
                </div>
            </div>
            <div class="bcontent">
		<?php
$limit = 8;
 if (isset($_GET['page'])) 
            {
                $page = $_GET['page'];
            } 
        else 
            {
                $page = 1;
            }
$offset = ($page - 1) * $limit;
 if (isset($_POST["txts"]))
            {   
            $search =$con->real_escape_string($_POST["txts"]);
            $querry =$con->query("(select id, name, image, info, price from product where name LIKE '%{$search}%' ) union (select id, name, image, info, price from footwear where name LIKE '%{$search}%' ) LIMIT {$limit} offset {$offset}");
            $querry2 =$con->query("(select id, name, image, info, price from product where name LIKE '%{$search}%' ) union (select id, name, image, info, price from footwear where name LIKE '%{$search}%' )");
            $result = $querry2->num_rows; 
            }
 elseif (isset($_GET["search"]))
            {   
            $search =$con->real_escape_string($_GET["search"]);
            $querry =$con->query("(select id, name, image, info, price from product where name LIKE '%{$search}%' ) union (select id, name, image, info, price from footwear where name LIKE '%{$search}%' ) LIMIT {$limit} offset {$offset}");
            $querry2 =$con->query("(select id, name, image, info, price from product where name LIKE '%{$search}%' ) union (select id, name, image, info, price from footwear where name LIKE '%{$search}%' )");
            $result = $querry2->num_rows; 
            }
            $row3 = $result;
            $pages = ceil($row3 / $limit);
            $offset = ($page - 1) * $limit;
while ($row = mysqli_fetch_array($querry))
{
?>
            <div class="bsp">
                <form method="post" action="cart.php">
                    <input type="hidden" name="name" value="<?php echo $row["name"]; ?>"></input>
                    <input type="hidden" name="id" value="<?php echo $row["id"]; ?>"></input>
                    <input type="hidden" name="price" value="<?php echo $row["price"]; ?>"></input>
                    <input type="hidden" name="image" value="<?php echo $row["image"]; ?>">
                    <input type="hidden" name="num" value="1"></input>
                <a href="listdetail.php?index=<?php echo $row['id'] ;?>"><img src="<?php echo $row["image"] ?>"/></a>
                <div class="bgia"><?php echo $row["name"]; ?></div>
                <div class="bgia"><div class="btext">Giá: </div><div class="color"><?php echo $row["price"] . " VNĐ"; ?></div></div>
                <div class="bgia"><input type="submit" value="Thêm vào giỏ hàng" name="addcart"/></div>
                </form>
            </div>
 <?php
}
 ?>
		</div>
               </div>
<?php include 'menu_right.php'; ?>
</div>
     <br />
<div class="pages">
         <?php
         if(isset($_GET["search"]))
             {
             for($i=1;$i <= $pages; $i++)
                {
                    echo "<a href=\"search.php?search={$search}&&page={$i}\">{$i}</a> "." ";
                }
             }
         else
            {
             for($i=1;$i <= $pages; $i++)
            {
                echo "<a href=\"search.php?search={$search}&&page={$i}\">{$i}</a> "." ";
            }
            }
         ?>
    </div>
<div class="footer">
We are... Mr.Chuot Tru, Mr.Minh Ho
<hr  width="20%" style="margin-left:40%; margin-top:8px;"/>
<pre><br /><br />
Coppyright: Aitieducation
</pre>
</div>
</div>
</body>
</html>
